<template>
  <div>
    <div class="page-index">
      <div>
        <div class="table-search">
          <el-form inline>
            <el-form-item label="名称">
              <el-input v-model="queryParams.name" size="mini" placeholder="请输入" />
            </el-form-item>
            <el-form-item label="提交人">
              <el-input v-model="queryParams.submitUser" size="mini" placeholder="请输入" />
            </el-form-item>
            <el-form-item>
              <el-button size="mini" type="primary" @click="search">搜索</el-button>
              <el-button size="mini" @click="reset">重置</el-button>
            </el-form-item>
          </el-form>
          <el-form inline>
            <el-form-item>
              <el-button size="mini" type="primary" @click="openAdd">新增</el-button>
            </el-form-item>
          </el-form>
        </div>
        <div class="table-box">
          <el-table
            :data="tableData"
            height="100%"
          >
            <el-table-column prop="id" label="ID" align="center" width="50" />
            <el-table-column prop="name" label="名称" align="center" min-width="150" />
            <el-table-column prop="studyTime" label="学习时间" align="center" width="160" />
            <el-table-column prop="studyAddress" label="学习地点" align="center" min-width="150" />
            <el-table-column prop="submitUser" label="提交人" align="center" min-width="120" />
            <el-table-column prop="submitTime" label="提交时间" align="center" width="160" />
            <el-table-column label="操作" align="center" width="120">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  size="mini"
                  @click="openDetail(scope.row)"
                >查看</el-button>
                <el-button
                  type="text"
                  size="mini"
                  style="color:#F56C6C;"
                  @click="openDelete(scope.row)"
                >删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <pagination
          :total="total"
          :page.sync="queryParams.pageNo"
          :limit.sync="queryParams.pageSize"
          @pagination="getData"
        />
      </div>
      <detailPage ref="detailPage" />
    </div>
  </div>
</template>
<script>
import detailPage from './components/detail'
import { queryByCondition, deleteById } from '@/api/onlineClassroom/studyNotes'
export default {
  components: {
    detailPage
  },
  data () {
    return {
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        name: '',
        submitUser: ''
      },
      total: 0,
      tableData: []
    }
  },
  mounted () {
    this.getData()
  },
  methods: {
    getData () {
      queryByCondition(this.queryParams).then((res) => {
        this.tableData = res?.data?.records || []
        this.total = res?.data?.total || 0
      })
    },
    search () {
      this.queryParams.pageNo = 1
      this.getData()
    },
    // openAdd () {
    //   this.$refs.addOrEdit.open({})
    // },
    // openEdit (row) {
    //   this.$refs.addOrEdit.open(row)
    // },
    openDelete (row) {
      this.$confirm('是否确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteById({ id: row.id }).then((res) => {
          this.$message.success('删除成功')
          this.getData()
        })
      })
    },
    openDetail (row) {
      this.$refs.detailPage.open(row)
    },
    reset () {
      this.queryParams.name = ''
      this.queryParams.submitUser = ''
      this.search()
    }
  }
}
</script>
<style scoped lang="scss">
.page-index {
  padding-top: 24px;
  .table-search {
    display: flex;
    justify-content: space-between;
    padding-left:16px;
  }
  .table-box {
    height: calc(100vh - 230px);
  }
}

</style>
